package com.wolfheader.wolfgame.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wolfheader.wolfgame.dao.admin.GamePlayerDao;
import com.wolfheader.wolfgame.entity.GamePlayerEntity;
import com.wolfheader.wolfgame.service.GamePlayerService;

/**
 * ServiceImpl -
 * 
 * @author 8615 Team
 * @version 1.0
 */
@Service("gamePlayerServiceImpl")
public class GamePlayerServiceImpl implements GamePlayerService {

	@Autowired
	private GamePlayerDao gamePlayerDao;

	@Override
	public GamePlayerEntity editGamePlayer(Map<String, Object> userInfoMap) {
		GamePlayerEntity player = gamePlayerDao.findByOpenid((userInfoMap.get("openid").toString()));
		// if (player == null) {
		// player = new GamePlayerEntity();
		// player.setOpenid(userInfoMap.get("openid").toString());
		// player.setCity(userInfoMap.get("city").toString());
		// player.setCountry(userInfoMap.get("country").toString());
		// player.setHeadimgurl(userInfoMap.get("headimgurl").toString());
		// player.setNickname(userInfoMap.get("nickname").toString());
		// player.setProvince(userInfoMap.get("province").toString());
		// player.setSex(userInfoMap.get("sex").toString());
		// player.setPlayCount(1);
		// gamePlayerDao.save(player);
		// } else {
		// Integer playerCount = player.getPlayCount() + 1;
		// player.setPlayCount(playerCount);
		// player.setCity(userInfoMap.get("city").toString());
		// player.setCountry(userInfoMap.get("country").toString());
		// player.setHeadimgurl(userInfoMap.get("headimgurl").toString());
		// player.setNickname(userInfoMap.get("nickname").toString());
		// player.setProvince(userInfoMap.get("province").toString());
		// player.setSex(userInfoMap.get("sex").toString().toString());
		// }
		return player;
	}

	/***
	 * 根据openid 获取玩家
	 */
	@Override
	public GamePlayerEntity findPlayerByOpenid(String openid) {

		return gamePlayerDao.findByOpenid(openid);
	}

	@Override
	public void updatePlayerInfo(GamePlayerEntity player) {
		gamePlayerDao.save(player);
	}
}
